<template>
  <div class="block">
    <el-table :data="logs" style="width: 100%">
      <el-table-column type="index" label="序号" width="50"></el-table-column>
      <el-table-column prop="username" label="登录用户" width="180"></el-table-column>
      <el-table-column prop="ip_address" label="用户IP" width="180"></el-table-column>
      <el-table-column prop="desc" label="状态"></el-table-column>
      <el-table-column label="时间">
        <template slot-scope="scope">
          {{ scope.row.login_time | timeFilter }}
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import { userLogList } from "@/api/user";
import { parseTime } from "@/utils/index";
export default {
  name: "UserLog",
  filters: {
    timeFilter(login_time) {
      return parseTime(new Date(login_time));
    }
  },

  data() {
    return {
      logs: []
    };
  },
  methods: {
    getUserLog() {
      userLogList()
        .then(res => {
          console.log(res);
          this.logs = res.results;
        })
        .catch(error => {
          console.log(error);
        });
    }
  },
  created() {
    this.getUserLog();
  }
};
</script>